package com.mmall.concurrency.example.syncContainer;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.mmall.concurrency.annoations.NotThreadSafe;
import lombok.extern.slf4j.Slf4j;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Vector;

@NotThreadSafe
@Slf4j
public class SyncMapExample {

    private static List<Integer> list = Collections.synchronizedList(Lists.newArrayList());

    public static void main(String[] args) {

        while (true) {

            for (int i = 0; i < 10; i++) {
                list.add(i);
            }

            Thread thread1 = new Thread() {
                public void run() {
                    for (int i = 0; i < list.size(); i++) {
                        list.remove(i);
                        log.info("remove:{}",i);
                    }
                }
            };

            Thread thread2 = new Thread() {
                public void run() {
                    for (int i = 0; i < list.size(); i++) {
                        log.info("get:{}", list.get(i));
                        list.get(i);
                    }
                }
            };
            thread1.start();
            thread2.start();
        }
    }
}
